﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace Cangku.cy
{
    public partial class CKXX : Form
    {

        public CKXX()
        {
            InitializeComponent();
        }

        private void 添加仓库信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TianJ tj = new TianJ();
            tj.Owner = this;
            tj.Show();
        }

        private void 修改仓库信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //获取当前选中行
            DBHelper db = new DBHelper();
            int id = Convert.ToInt32(this.dataGridView1.SelectedRows[0].Cells[0].Value);
            XiuG xg = new XiuG();
            xg.ckid = id;
            xg.Owner = this;
            xg.Show();
        }

        private void CKXX_Load(object sender, EventArgs e)
        {
            LoadCangku();
            DateTime sj = DateTime.Now;
            this.toolStripStatusLabel1.Text = sj.ToString();
            this.timer1.Start();
            string sql = string.Format("select * from Information where CKzhuang='{0}'",true);
            DataTable dt = DBHelper.Instance().GetDataTableBySql(sql);
            this.dataGridView1.AutoGenerateColumns = false;
            this.dataGridView1.DataSource = dt;
        }

        private void 删除仓库信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int id = Convert.ToInt32(this.dataGridView1.SelectedRows[0].Cells[0].Value);
            MessageBox.Show("是否确认删除该仓库信息", "提示信息",MessageBoxButtons.YesNo);
            if (true)
            {
                DBHelper db = new DBHelper();
                string sql = string.Format("update Information set CKzhuang ='0' where ID='{0}'", id);
                db.ExcuteSql(sql);
                LoadCangku();
            }

        }

        private void fh_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            this.toolStripStatusLabel1.Text = DateTime.Now.ToString();
        }
        public void LoadCangku()
        {
            DBHelper db = new DBHelper();
            string sql = string.Format("select * from Information where CKzhuang='{0}'",true);
            this.dataGridView1.AutoGenerateColumns = false;
            this.dataGridView1.DataSource = db.GetDataTableBySql(sql);
        }
    }
}
